package com.ruoyi.yijing.service.impl;

import java.util.List;
import java.util.concurrent.TimeUnit;

import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.yijing.mapper.CustomerInfoMapper;
import com.ruoyi.yijing.domain.CustomerInfo;
import com.ruoyi.yijing.service.ICustomerInfoService;

import static com.ruoyi.common.constant.CacheConstants.CACHE_PRE;

/**
 * 客户信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-22
 */
@Service
public class CustomerInfoServiceImpl implements ICustomerInfoService 
{
    @Autowired
    private CustomerInfoMapper customerInfoMapper;

    @Autowired
    private RedisCache redisCache;

    /**
     * 查询客户信息
     * 
     * @param customerUid 客户信息主键
     * @return 客户信息
     */
    @Override
    public CustomerInfo selectCustomerInfoByCustomerUid(Long customerUid)
    {
        String key = CACHE_PRE+"CustomerInfo_2"+customerUid;
        CustomerInfo customerInfo = redisCache.getCacheObject(key);
        if (customerInfo == null){
            customerInfo = customerInfoMapper.selectCustomerInfoByCustomerUid(customerUid);
            if (customerInfo != null){
                redisCache.setCacheObject(key,customerInfo,5, TimeUnit.MINUTES);
            }
        }
        return customerInfo;
    }

    /**
     * 查询客户信息列表
     * 
     * @param customerInfo 客户信息
     * @return 客户信息
     */
    @Override
    public List<CustomerInfo> selectCustomerInfoList(CustomerInfo customerInfo)
    {
        return customerInfoMapper.selectCustomerInfoList(customerInfo);
    }

    /**
     * 新增客户信息
     * 
     * @param customerInfo 客户信息
     * @return 结果
     */
    @Override
    public int insertCustomerInfo(CustomerInfo customerInfo)
    {
        customerInfo.setCreateTime(DateUtils.getNowDate());
        return customerInfoMapper.insertCustomerInfo(customerInfo);
    }

    /**
     * 修改客户信息
     * 
     * @param customerInfo 客户信息
     * @return 结果
     */
    @Override
    public int updateCustomerInfo(CustomerInfo customerInfo)
    {
        customerInfo.setUpdateTime(DateUtils.getNowDate());
        return customerInfoMapper.updateCustomerInfo(customerInfo);
    }

    /**
     * 批量删除客户信息
     * 
     * @param customerUids 需要删除的客户信息主键
     * @return 结果
     */
    @Override
    public int deleteCustomerInfoByCustomerUids(Long[] customerUids)
    {
        return customerInfoMapper.deleteCustomerInfoByCustomerUids(customerUids);
    }

    /**
     * 删除客户信息信息
     * 
     * @param customerUid 客户信息主键
     * @return 结果
     */
    @Override
    public int deleteCustomerInfoByCustomerUid(Long customerUid)
    {
        return customerInfoMapper.deleteCustomerInfoByCustomerUid(customerUid);
    }
}
